package com.master.train.batch.controller;


import com.master.train.batch.req.CronJobReq;
import com.master.train.common.utils.R;
import org.quartz.JobKey;
import org.quartz.SchedulerException;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/job")
public class JobController {
    private SchedulerFactoryBean schedulerFactoryBean;

    @RequestMapping("/run")
    public R run(@RequestBody CronJobReq cronJobReq) throws SchedulerException {
        String cronJobReqName = cronJobReq.getName();
        String cronJobReqGroup = cronJobReq.getGroup();
        schedulerFactoryBean.getScheduler().triggerJob(JobKey.jobKey(cronJobReqName,cronJobReqGroup));
        return R.ok();
    }


}
